<template>
	<view class="container">
		<button type="primary" @click="navToAdd">新增</button>
		<view v-model="queryParams.location">当前位置：</view>
		<uni-list>
			<uni-list-item v-for="(item, index) in recordList" :key="index1" :title="item.name"
                     :rightText="item.arriveTimeStr" :note="item.splict" />
		</uni-list>
	</view>
</template>

<script>
	import {
		listRecord
	} from "@/api/system/record"
	import {
		getMerchant
	} from "@/api/system/merchant"

	export default {
		data() {
			return {
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					merchantId: null,
					userId: null,
					collectionDate: null,
					location: null,
					arriveTime: null,
					groundQuantity: null,
					groundPrice: null,
					undergroundQuantity: null,
					stoveQuantity: null
				},
				recordList: [],
				merchant: {
					id: '1'
				}
			}
		},
		onLoad(options) {
			// 获取扫码中商户id
			this.merchant.id = options.merchantId;
			// 查询商户收运记录
			this.queryListRecord()
			// 查询商户信息
			this.queryMerchant()
		},
		methods: {
			queryListRecord() {
				this.queryParams.merchantId = this.merchant.id;
				// 获取收运记录
				listRecord(this.queryParams).then(response => {
					this.recordList = response.rows
					console.log(this.recordList)
					this.recordList.forEach(item => {
						item.arriveTimeStr = this.formatDate(item.arriveTime)

						item.splict = "GPS定位坐标：" + item.location +
							"；地上油收油量：" + item.groundPrice +
							"；地上油单价：" + item.groundQuantity +
							"；地下油收油量：" + item.undergroundQuantity +
							"；灶台油收油量：" + item.stoveQuantity
					})
				})
			},
			queryMerchant() {
				// 获取商户信息
				getMerchant(this.merchant.id).then(response => {
					console.log(response.data)
				})
			},
			// 跳转新增
			navToAdd() {
				uni.navigateTo({
					url: `./add?merchantId=` + this.merchant.id
				});
			},
			formatDate(value) {
				const data = new Date(value);
				const month = data.getMonth() + 1;
				const day = data.getDate();
				const year = data.getFullYear();
				const hours = data.getHours();
				const minutes = data.getMinutes();
				const seconds = data.getSeconds();
				const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
				return formattedTime;

			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}
</style>
